<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <lk-box ref='box1'></lk-box>
      <button @click="getChildComponent">获取子组件</button>
    </div>

    <template id="box">
      <div style="background-color: bisque;width: 200px;height: 200px;">
        <button @click="btnClick">点我</button>
      </div>
    </template>
    <script src="../js/vue.js"></script>

    <script>

      //定义一个子组件
      const Box = {
        data(){
          return {
            child:124
          }
        },
        methods:{
          btnClick(){
            console.log('click me');
          }
        },
        template:"#box"
      }

      //实例化vue
      const app = Vue.createApp({
        data() {
          return {
            msg: ""
          }
        },
        components:{
          'lk-box':Box
        },
        methods:{
          //获取子组件
          getChildComponent(){
            //this.$refs//获取子组件
            console.log(this.$refs);//拿到子组件的东西
            console.log(this.$refs.box1);
            console.log(this.$refs.box1.child);
            this.$refs.box1.btnClick();

          }
        }
      }).mount("#app");
    </script>
  </body>
</html>